package cn.liccshop.core.service.shopUserAddress.service;

import cn.liccshop.core.entity.ShopUserAddress;
import cn.liccshop.core.service.shopUserAddress.mapper.ShopUserAddressMapper;
import cn.liccshop.core.service.shopUserAddress.service.IShopUserAddressService;
import cn.liccshop.sys.constants.Constants;
import cn.liccshop.sys.exception.MySystemException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户收货地址表 服务实现类
 * </p>
 *
 * @author LiCC
 * @since 2019-05-06
 */
@Service
public class ShopUserAddressServiceImpl extends ServiceImpl<ShopUserAddressMapper, ShopUserAddress> implements IShopUserAddressService {

    @Override
    public ShopUserAddress saveAddressInfo(ShopUserAddress address) throws MySystemException {
        boolean isSuccess = false;
        if (StringUtils.isBlank(address.getId())){
            /** 插入操作 **/
            isSuccess = retBool(baseMapper.insert(address));
        } else {
            /** 更新操作 **/
            baseMapper.deleteById(address.getId());
            isSuccess = retBool(baseMapper.insert(address.setId(null)));
        }
        if (!isSuccess){
            throw new MySystemException("信息保存失败", Constants.SERVICE_FAIL);
        }
        return address;
    }
}
